import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

path = 'msedgedriver.exe'
browser = webdriver.Edge(path)

# 最大化窗口
browser.maximize_window()

# 访问页面
url = 'http://localhost:90'
browser.get(url)

# 登陆
name = browser.find_element(By.XPATH, "//*[@id='username']")
name.send_keys('admin')
password = browser.find_element(By.XPATH, "//*[@id='password']")
password.send_keys('123456')
login = browser.find_element(By.XPATH, "//*[@id='login_btn']")
login.click()

# 进入零钱理财
WebDriverWait(browser, 5, 0.5).until(
    EC.presence_of_element_located((By.XPATH, "//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/a[1]")))
licai = browser.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/a[1]")
licai.click()

WebDriverWait(browser, 5, 0.5).until(
    EC.presence_of_element_located((By.XPATH, "//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/ul[1]/li[1]/a[1]")))
lingqianlicai = browser.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/ul[1]/li[1]/a[1]")
lingqianlicai.click()

# 修改“新增数据”按钮的文本为“添加”
WebDriverWait(browser, 5, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[@id='add_modal_btn']")))
add_button = browser.find_element(By.XPATH, "//*[@id='add_modal_btn']")
browser.execute_script("""
    arguments[0].innerText = '新增喵~';
""", add_button)

# # 新增数据
# for i in range(20):
#     WebDriverWait(browser, 5, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[@id='add_modal_btn']")))
#     add = browser.find_element(By.XPATH, "//*[@id='add_modal_btn']")
#     add.click()
#     time.sleep(1.5)
#
#     chanpin_name = browser.find_element(By.XPATH, "//*[@id='name_add_input']")
#     chanpin_name.send_keys(f'测试产品{i}')
#
#     qirinianhuashouyi = browser.find_element(By.XPATH, "//*[@id='annualincome_add_input']")
#     qirinianhuashouyi.send_keys(f'{i}')
#
#     wanyuanshouyi = browser.find_element(By.XPATH, "//*[@id='peiincome_add_input']")
#     wanyuanshouyi.send_keys(f'{i}')
#
#     qitoujine = browser.find_element(By.XPATH, "//*[@id='invesmoney_add_input']")
#     qitoujine.send_keys(f'{i}')
#
#     baocun = browser.find_element(By.XPATH, "//*[@id='save_btn']")
#     baocun.click()
#     time.sleep(2)
#
# browser.quit()
